package com.zmm.util.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * 配置线程池
 * @author 900045
 * @description:
 * @name MyThreadConfig
 * @date By 2021-06-29 14:19:11
 */
@Configuration
public class MyThreadConfig {

	/**
	 * 线程池维护线程的最少数量
	 */
	private int   coreSize  = 10;

	/**
	 * 线程池维护线程的最大数量
	 */
	private int   maxSize   = 30;


	/**
	 * 允许的空闲时间
	 */
	private int   keepAliveTime   = 60;

	@Bean
	public ThreadPoolExecutor threadPoolExecutor(){
		return new ThreadPoolExecutor(
				coreSize,
				maxSize,
				keepAliveTime,
				TimeUnit.SECONDS,
				new LinkedBlockingDeque<>(100000),
				Executors.defaultThreadFactory(),
				new ThreadPoolExecutor.AbortPolicy());
	}
}
